/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package modelos_programa;

import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

/**
 *
 * @author HUSSEIN
 */
public class HistogramaDiscreto extends javax.swing.JDialog {
    Operaciones_SQL operaciones;
    /**
     * Creates new form HistogramaContinuo
     */
    public HistogramaDiscreto(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();  
        setLocationRelativeTo(null);
        setResizable(false);
        
        setDefaultCloseOperation (WindowConstants.DO_NOTHING_ON_CLOSE);

        addWindowListener(new WindowAdapter(){
        @Override
        public void windowClosing(WindowEvent we){
            dispose();
	}
        });
        
        operaciones = new Operaciones_SQL();
        operaciones.conectar();
        graficarHistoDiscreto();
    }
    
    public void graficarHistoDiscreto(){
        try {
            Grafico migrafico = new Grafico();
            //tamaño del grafico
            Dimension d = panelHistoDist.getSize();//toma el tamaño del contenedor
            
            ArrayList dist = new ArrayList(); //guardara los datos de la columna FE

            operaciones.llenarArray_DISCRETA(dist); 
            
            
            int x = dist.size();
            double vector[] = new double[x];
            
            for (int i=0;i<x;i++){
                vector[i]=(double) dist.get(i);
            }
            
            
            //se crea el grafico
            migrafico.crear_grafico_histograma(d, vector,"Series Discretas","Histograma Datos Discretos", 10);
            //se crea un jlabel para colocar el grafico
            JLabel j = new JLabel();
            j.setBounds(0, 0, d.width, d.height);
            //se carga el grafico de memoria
            migrafico.cargar_grafico(j);
            //se añade al contenedor
            panelHistoDist.add(j);
            this.repaint();
        } catch (SQLException ex) {
            Logger.getLogger(ventanaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
    
} 

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelHistoDist = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        javax.swing.GroupLayout panelHistoDistLayout = new javax.swing.GroupLayout(panelHistoDist);
        panelHistoDist.setLayout(panelHistoDistLayout);
        panelHistoDistLayout.setHorizontalGroup(
            panelHistoDistLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 710, Short.MAX_VALUE)
        );
        panelHistoDistLayout.setVerticalGroup(
            panelHistoDistLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 458, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelHistoDist, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelHistoDist, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(HistogramaDiscreto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(HistogramaDiscreto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(HistogramaDiscreto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(HistogramaDiscreto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                HistogramaDiscreto dialog = new HistogramaDiscreto(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JPanel panelHistoDist;
    // End of variables declaration//GEN-END:variables
}
